object Test3 {
  def main(args: Array[String]): Unit = {
    val p1 = new Points(2,3)
    val p2 = new Points(2,4)
    val p3 = new Points(3,3)
    println(p1.isNotEqual(p2))
    println(p1.isNotEqual(p3))
    println(p1.isNotEqual(2))
  }
}

//定义特质
trait Equal {
  def isEqual(x:Any):Boolean  //抽象方法
  def isNotEqual(x:Any):Boolean = !isEqual(x)
}

//继承特质
class Points(xc:Int, yc:Int) extends Equal {
  var x:Int = xc
  var y:Int = yc
  def isEqual(obj:Any) = obj.isInstanceOf[Points] && obj.asInstanceOf[Points].x == x  //重写抽象字段和方法
}
